/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.charge.dao.impl;


import java.util.List;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.charge.dao.IParameterDefDao;
import com.ce.pms.charge.model.ParameterDefDomain;
import com.ce.pms.charge.vo.ParameterDefVO;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：参数预设<br>
 * @author 罗军林 创建日期：2008-8-6
 */
public class ParameterDefDaoImpl extends PmsBaseDaoImpl<ParameterDefDomain> implements
		IParameterDefDao {

	/* (non-Javadoc)
	 * @see com.ce.pms.charge.dao.IParameterDefDao#queryParameterDef(com.ce.pms.charge.vo.ParameterDefVO, int, int)
	 */
	public Page queryParameterDef(ParameterDefVO condition, int pageNo, int pageSize) {
		StringBuffer sql=new StringBuffer("FROM ParameterDefDomain p where 1=1 ");
		sql.append(buildCondition(condition));

		return this.pagedQueryByPageNo(sql.toString(), pageNo, pageSize);
	}

	/**
	 * 功能描述:查找指定模块指定引用值的参数预设记录<br>
	 * @param pkey
	 * @param gkey
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-17<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public ParameterDefDomain findByPkGk(Long pkey,String gkey){
		String hql="FROM ParameterDefDomain p where p.pvalue=? and p.gkey=?";
		Query query=createQuery(hql, pkey,gkey);
		return (ParameterDefDomain)query.uniqueResult();
	}


	public List<ParameterDefDomain> getNotInCode(String temStr){
		//MULTIPLE_PAY_CODE  PRE_PAY_CODE BANK_PAID_CODE

		String hql="FROM ParameterDefDomain p where p.pkey in("+temStr+")";

		Query query=createQuery(hql);
		return query.list();
	}

	/**
	 * 功能描述:构建查询条件<br>
	 * @param condition
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String buildCondition(ParameterDefVO condition){
		StringBuffer result=new StringBuffer();
		if(condition == null ){
			return "";
		}else if(condition.getGkey() != null || condition.getGkey().trim() != ""){
			result.append("and p.gkey='").append(condition.getGkey()).append("' ");
		}
		return result.toString();
	}


}
